﻿using System.Collections.Generic;
using System.Linq;
using UnityEngine;


namespace RStudio.Elevator
{
    /// <summary>
    /// 模块|驱动管理中心
    /// </summary>
    public class ElevatorModuleDriven
    {
        public ElevatorModuleDriven()
        { 
            this.Drivens = new HashSet<ElevatorDriven>();
        }

        /// <summary>
        /// 
        /// </summary>
        public HashSet<ElevatorDriven> Drivens { get; private set; }


        /// <summary>
        /// 注册|电梯驱动
        /// </summary>
        public void Register(ElevatorDriven driven)
        {
            Drivens.Add(driven);
            Debug.Log($"<b>[ElevatorModuleDriven]</b> {driven.Component.Key} 注册了电梯驱动中心");
        }

        /// <summary>
        /// 注销|电梯驱动
        /// </summary>
        public void UnRegister(ElevatorDriven driven)
        { 
            this.Drivens.Remove(driven);
        }

        /// <summary>
        /// 获取|电梯驱动
        /// </summary>
        public ElevatorDriven Get(string name)
        {
            return this.Drivens.ToList().Find(e => e.Component.Key == name);
        }
    }
}
